package com.xiaoxin.errorDemo.async;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Component;

import java.util.concurrent.Future;

@Async
@Slf4j
@Component
public class AsyncTask {

    public void task1() {
        try {
            Thread.sleep(4000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        log.info(" task 1 ");
    }

    public void task2() {
        try {
            Thread.sleep(4000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        log.info(" task 2 ");
    }

    public void task3() {
        try {
            Thread.sleep(4000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        log.info(" task 3 ");
    }

    public Future<String> task4() {
        try {
            Thread.sleep(4000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        log.info(" task 4 ");
        return new AsyncResult<>("task4");
    }

    public Future<String> task5() {
        try {
            Thread.sleep(5000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        log.info(" task 5 ");
        return new AsyncResult<>("task5");
    }

}